import { createReducer } from '../utils/index'
import { FETCH_SORTS_SUCC, FETCH_SORTS_FAIL, FETCH_GOODS_FROM_SORT_SUCC, FETCH_GOODS_FROM_SORT_FAIL } from '../contants/sort'

const initialState = {
	sortsFetched: null,
	sortsData: [],
	goodsFetched: null,
	goodsData: []
}

export default createReducer(initialState, {
	[FETCH_SORTS_SUCC]: (state, payload) => {
		 return Object.assign({}, state, {
			'sortsFetched': true,
			'sortsData': payload.data
		})
	},

	[FETCH_SORTS_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'sortsFetched': false,
            'sortsData': []
        });
    },

    [FETCH_GOODS_FROM_SORT_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'goodsFetched': true,
            'goodsData': payload.data
        });
    },

    [FETCH_GOODS_FROM_SORT_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'goodsFetched': false,
            'goodsData': []
        });
    },
})
